package display.tween 
{
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	/**
	 * ...
	 * @author deve.huang
	 * 
	 * 单个属性执行Tween效果
	 */
	
	 
	public class TweenRotationX 
	{
		private var _sp:DisplayObject;
		
		private var _trx:Number;
		private var _endValue:Number;
		private var _speed:Number;
		private var _funcOnEnd:Function;
		
		private var card:Sprite;
		
		public function TweenRotationX(sp:DisplayObject, rx:Number, endValue:Number = .2, speed:Number = .3, funcOnEnd:Function = null) 
		{
			_funcOnEnd = funcOnEnd;
			_sp = sp;
			
			_trx = rx;
			
			_endValue = endValue;
			_speed = speed;
			
			//card = new Sprite;
			//card.addChild(_sp);
			
			//sp.y = 
			
			_sp.addEventListener(Event.ENTER_FRAME, fxHandler);
		}
		
		private function fxHandler(e:Event):void 
		{
			var d:Number = _trx - _sp.rotationX;
			_sp.rotationX += d * _speed;
			
			if (Math.abs(d) < _endValue) {
				_sp.removeEventListener(Event.ENTER_FRAME, fxHandler);
				_sp.rotationX  = _trx;
				delete this;
				
				if(_funcOnEnd != null) _funcOnEnd();
			}
		}
		public function clean():void
		{
			_sp.removeEventListener(Event.ENTER_FRAME, fxHandler);
			_sp.rotationX  = _trx;
			
			if(_funcOnEnd != null) _funcOnEnd();
			delete this;
		}
		
	}
}